var m_callback;
var m_cticlient;
function createIframe(id) {
	try {
		var iframe = document.createElement('iframe');
	    iframe.name = id;
	    iframe.id = id;
	    return iframe;
	} catch (err) {
	  	console.log(err.stack);
	}
}
	
function createctiiframe() {
    var iframe = document.getElementById("cti")
    if (!iframe) {
        console.log('create cti Iframe');
        var iframe = createIframe('cti');
        iframe.src = $E.softphoneBasePath + '/softphone/trcloud/trcloudpage.html';
        iframe.style='visibility:hidden';
        iframe.width ='0';
        iframe.height='0';
        document.body.appendChild(iframe);
    } else {
        console.log('using cti Iframe');
        iframe.src = $E.softphoneBasePath + '/softphone/trcloud/trcloudpage.html';
    }
}

function iframeonload(cticlient) {
	console.log('iframeonload');
	//debugger;
	m_cticlient = cticlient;
	if (m_callback) {
		m_callback(m_cticlient);
	}
}
	
define([], function(){
	//createctiiframe();
	var CTIClientFactory = {
		getCTIClient: function(callback) {
			//debugger;
            createctiiframe();
    		//if (m_cticlient) {
    		//	callback(m_cticlient);
    		//} else {
        		m_callback = callback;
    		//}
    	}
    }
	return CTIClientFactory;
})